<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.staticfile.org/vue/3.0.5/vue.global.js"></script>
</head>

<body>
    <div id="app" class="demo">
        <ul>
            <li style=" width: 50%; background-color: antiquewhite;" 
            v-for="(item,index) in songs" 
            :key='item.id' 
            @click="change_item(item)">
                <h2>{{item.id}}-歌名： {{item.name}}</h2>
                <div> {{item.author}}</div>
                
                <hr>
            </li>
        </ul>

        <div style="margin-left: 15%;">
            <audio @ended="auto_listen()" autoplay controls :src="item_src"></audio>  
        </div>
        <button @click="next_song">下一曲</button>
    </div>
</body>
<script>

    const HelloVueApp = {
        data() {
            return {
                item_id: 1,
                // item_src: '../data_src/1.mp3',
                songs: [
                    {
                        id: 1,
                        name: '安和桥',
                        author: '张三',
                        src: '../data_src/1.mp3',
                    },
                    {
                        id: 2,
                        name: '董小姐',
                        author: '李四',
                        src: '../data_src/2.mp3',
                    },
                    {
                        id: 3,
                        name: '斑马，斑马',
                        author: '王五',
                        src: '../data_src/3.mp3',
                    }
                ],
            }

        },
        methods: {
            change_item(item) {
                console.log("******************88");
                console.log(item);
                this.item_id = item.id;
            },
            next_song() {
                console.log(this.item_id);
                if (this.item_id == this.songs.length) {
                    this.item_id = 1;
                } else {
                    this.item_id++;
                }
            },
            auto_listen(){
                this.next_song();
            }
        },
        computed: {
            //监听属性信息
            item_src: function () {
                return this.songs[this.item_id - 1].src;
            }
        }
    }
    Vue.createApp(HelloVueApp).mount('#app')
</script>

</html>